//
//  SopViewCell.m
//  DigiOps
//
//  Created by app on 2018/7/18.
//  Copyright © 2018年 俞渊华. All rights reserved.
//

#import "SopViewCell.h"

@implementation SopViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
//    [self.sopInfo setBackgroundImage:[UIImage imageNamed:@"sop_info"] forState:UIControlStateNormal];
//    [self.sopInfo addTarget:self action:@selector(infoClick) forControlEvents:UIControlEventTouchUpInside];
    self.okButton.tag=0;
    self.notokButton.tag=1;
    [self.okButton addTarget:self action:@selector(infoClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.notokButton addTarget:self action:@selector(infoClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.okButton setBackgroundColor:XMColor(241, 245, 247)];
    [self.notokButton setBackgroundColor:XMColor(241, 245, 247)];
    [self.okButton setBackgroundImage:[self createImageWithColor:XMColor(241, 245, 247)] forState:UIControlStateNormal];
    [self.okButton setBackgroundImage:[self createImageWithColor:XMColor(72, 187, 72)] forState:UIControlStateSelected];
    
    [self.notokButton setBackgroundImage:[self createImageWithColor:XMColor(241, 245, 247)] forState:UIControlStateNormal];
    [self.notokButton setBackgroundImage:[self createImageWithColor:DGColor] forState:UIControlStateSelected];

}
-(void)infoClick:(UIButton*)sender
{
    if ([MySingleton sharedMySingleton].finished)
    {
        if (sender.tag!=0) {
        if (self.block) {
            self.block();
        }
        }
    }
    else
    {
    sender.selected=!sender.selected;

    if (sender.tag==0) {
        if (sender.selected) {
            if (self.notokButton.selected) {
                self.notokButton.selected=!self.notokButton.selected;
            }
            if (self.blockOK) {
                self.blockOK();
            }
        }
    }
    else{
        if (sender.selected) {
            if (self.okButton.selected) {
                self.okButton.selected=!self.notokButton.selected;
            }
            if (self.block) {
                self.block();
            }
        }
        else
        {
            if (self.block) {
                self.block();
            }
            self.notokButton.selected=!self.notokButton.selected;

        }

    }
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+ (SopViewCell *)cellWithTableView:(UITableView *)tableView {
    static NSString *ID = @"SopViewCellID";
    
    SopViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[NSBundle mainBundle] loadNibNamed:@"SopViewCell" owner:nil options:nil].lastObject;
        cell.backgroundColor=[UIColor whiteColor];
        
    }
    return cell;
}
-(UIImage *)createImageWithColor:(UIColor *)color
{
    //设置长宽
    CGRect rect = CGRectMake(0.0f, 0.0f, 5.0f, 5.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return resultImage;
}
@end
